package com.fengdi.book.easy;


import java.util.ArrayList;
import java.util.Random;
import java.util.Stack;

public class DesignProblems {
    public static class Solution {
        private final int[] nums;
        private int[] shuffleArr;
        private Random rand = new Random();

        public Solution(int[] nums) {
            this.nums = nums;
            this.shuffleArr = this.nums.clone();
        }

        public int[] reset() {
            return this.nums;
        }

        public int[] shuffle() {
            if (this.nums == null)
                return null;

            this.shuffleArr = this.nums.clone();
            for (int j = 1; j < this.shuffleArr.length; j++) {
                int i = rand.nextInt(j + 1);
                swap(this.shuffleArr, i, j);
            }
            return this.shuffleArr;
        }

        private void swap(int[] arr, int i, int j) {
            int exchange = arr[i];
            arr[i] = arr[j];
            arr[j] = exchange;
        }
    }

    public static class MinStack {
        private final Stack<Integer> stack = new Stack<>();
        private int min = Integer.MAX_VALUE;

        public MinStack() {
        }

        public void push(int val) {
            if(val <= this.min) {
                this.stack.push(this.min);
                this.min = val;
            }
            this.stack.push(val);
        }

        public void pop() {
            if(this.stack.pop() == this.min) {
                this.min = this.stack.pop();
            }
        }

        public int top() {
            return this.stack.peek();
        }

        public int getMin() {
            return this.min;
        }
    }
}
